﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XYW.WebSite;

namespace xyw.admincp
{
    public partial class Friendes : System.Web.UI.Page
    {
        private XYW.BLL.News bllnews = new XYW.BLL.News();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            XYW.BLL.News bllNews = new XYW.BLL.News();
            string where = "classify in(select classifyName from News_Classify where type=1) order by id desc";
            if (SiteAbout.gStr("classify") != "")
            {
                where = "classify='" + SiteAbout.gStr("classify") + "' order by id desc";
                this.lt_Cname.Text = " - " + SiteAbout.gStr("classify");
            }
            this.Repeater1.DataSource = bllNews.GetList(where);
            this.Repeater1.DataBind();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = int.Parse(e.CommandArgument.ToString());
            XYW.Model.News modelNews = bllnews.GetModel(id);
            if (e.CommandName == "Delete")
            {
                bllnews.Delete(id);
            }
            if (e.CommandName == "Top")
            {
                modelNews.sortBy = 1;
                bllnews.Update(modelNews);
            }
            if (e.CommandName == "Top1")
            {
                modelNews.sortBy = 2;
                modelNews.showInHomepage = 1;
                bllnews.Update(modelNews);
            }
            if (e.CommandName == "Down")
            {
                modelNews.sortBy = 0;
                modelNews.showInHomepage = 0;
                bllnews.Update(modelNews);
            }
            BindData();
        }
    }
}